<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.3/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","images":"/images","scheme":"Muse","version":"8.3.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}};
  </script>
<meta property="og:type" content="website">
<meta property="og:title" content="Lawted&#39;s Blog">
<meta property="og:url" content="http://example.com/index.html">
<meta property="og:site_name" content="Lawted&#39;s Blog">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="Lawted Wu">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://example.com/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'en'
  };
</script>
<title>Lawted's Blog</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">Lawted's Blog</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>Home</a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>Tags</a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>Archives</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Lawted Wu</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">67</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/LAWTED" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;LAWTED" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



        </div>
      </div>
        <div class="back-to-top animated" role="button" aria-label="Back to top">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/07/01/2021-06-31-2021%E5%B9%B4%E5%85%AD%E6%9C%88/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/07/01/2021-06-31-2021%E5%B9%B4%E5%85%AD%E6%9C%88/" class="post-title-link" itemprop="url">2021年六月</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2021-07-01 21:29:30" itemprop="dateCreated datePublished" datetime="2021-07-01T21:29:30+08:00">2021-07-01</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-07-02 22:40:39" itemprop="dateModified" datetime="2021-07-02T22:40:39+08:00">2021-07-02</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>上次五月的总结忘记了，所以这次五月六月一起写，五月是做工月，不是在做工就是在做工的路上，六月是考试复习月，推掉了所有的工作，安安心心和朋友复习了两周，感觉第一次是这么拼的复习，求求来个高分，吐槽一下数据库，本来想用他拉拉分，最后没想到试卷难得不行，平时还总是迟交作业，七月重启Leetcode ，冲！</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/05/07/Python/python-%E6%9B%B4%E5%A4%9A/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/05/07/Python/python-%E6%9B%B4%E5%A4%9A/" class="post-title-link" itemprop="url">python - 更多</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>
      

      <time title="Created: 2021-05-07 09:26:03 / Modified: 09:26:36" itemprop="dateCreated datePublished" datetime="2021-05-07T09:26:03+08:00">2021-05-07</time>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/05/07/%E9%9A%8F%E7%AC%94/2021%E5%B9%B4%E5%9B%9B%E6%9C%88/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/05/07/%E9%9A%8F%E7%AC%94/2021%E5%B9%B4%E5%9B%9B%E6%9C%88/" class="post-title-link" itemprop="url">2021年四月</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>
      

      <time title="Created: 2021-05-07 09:17:16 / Modified: 09:18:21" itemprop="dateCreated datePublished" datetime="2021-05-07T09:17:16+08:00">2021-05-07</time>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="匆匆忙忙的四月"><a href="#匆匆忙忙的四月" class="headerlink" title="匆匆忙忙的四月"></a>匆匆忙忙的四月</h2><p>从四月一号过完愚人节，就开始了匆匆忙忙的四月，四月二号面试腾讯的一面，然后到4月23号入职腾讯，之前准备了很久的字节倒是没了消息，入职以后就开始筹备五一回汉的事情，匆匆忙忙的学车，匆匆忙忙的考车，然后又匆匆忙忙的回京，四月的开始了打力扣的周赛，前两次感觉还不错，第三次就感觉总离答案差一点，然后只做出来一题掉分，四月的题目刷的没有三月的认真，可能是已经入职了的原因，写到这里突然想到每一题没有写（还有10分钟就第二天），赶紧ctrl c v去了</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/25/Python/python-%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/04/25/Python/python-%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" class="post-title-link" itemprop="url">Python - 数据结构</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2021-04-25 21:13:22" itemprop="dateCreated datePublished" datetime="2021-04-25T21:13:22+08:00">2021-04-25</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-05-07 09:34:08" itemprop="dateModified" datetime="2021-05-07T09:34:08+08:00">2021-05-07</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h1 id="python-数据结构"><a href="#python-数据结构" class="headerlink" title="python 数据结构"></a>python 数据结构</h1><p>Python有四种内置的数据结构</p>
<ul>
<li>列表(List)</li>
<li>元组(Tuple)</li>
<li>字典(Dictionary)</li>
<li>集合(Set)</li>
</ul>
<h2 id="列表"><a href="#列表" class="headerlink" title="列表"></a>列表</h2><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">shoplist = [<span class="string">&#x27;apple&#x27;</span>,<span class="string">&#x27;mango&#x27;</span>,<span class="string">&#x27;carrot&#x27;</span>,<span class="string">&#x27;banana&#x27;</span>]</span><br><span class="line"></span><br><span class="line">print(<span class="string">&#x27;I have&#x27;</span>,<span class="built_in">len</span>(shoplist),<span class="string">&#x27;items to purchase&#x27;</span>)</span><br><span class="line"></span><br><span class="line">print(<span class="string">&#x27;These items are: &#x27;</span>,end= <span class="string">&#x27;&#x27;</span>)</span><br><span class="line"><span class="keyword">for</span> item <span class="keyword">in</span> shoplist:</span><br><span class="line">    print(item,end = <span class="string">&#x27;&#x27;</span>)</span><br><span class="line"></span><br><span class="line">print(<span class="string">&#x27;\nI also have to buy rice.&#x27;</span>)</span><br><span class="line">shoplist.append(<span class="string">&#x27;rice&#x27;</span>)</span><br><span class="line">print(<span class="string">&#x27;My shopping list is now&#x27;</span>,shoplist)</span><br><span class="line"></span><br><span class="line">print(<span class="string">&#x27;I will sort my list now&#x27;</span>)</span><br><span class="line">shoplist.sort()</span><br><span class="line">print(<span class="string">&#x27;Sorted shopping list is&#x27;</span>,shoplist)</span><br><span class="line"></span><br><span class="line">print(<span class="string">&#x27;The first item I will buy is&#x27;</span>,shoplist[<span class="number">0</span>])</span><br><span class="line">olditem = shoplist[<span class="number">0</span>]</span><br><span class="line"><span class="keyword">del</span> shoplist[<span class="number">0</span>]</span><br><span class="line">print(<span class="string">&#x27;I bought the &#x27;</span>,olditem)</span><br><span class="line">print(<span class="string">&#x27;My shopping list is now&#x27;</span>,shoplist)</span><br><span class="line"></span><br><span class="line"><span class="comment">#I have 4 items to purchase</span></span><br><span class="line"><span class="comment">#These items are: applemangocarrotbanana</span></span><br><span class="line"><span class="comment">#I also have to buy rice.</span></span><br><span class="line"><span class="comment">#My shopping list is now [&#x27;apple&#x27;, &#x27;mango&#x27;, &#x27;carrot&#x27;, &#x27;banana&#x27;, &#x27;rice&#x27;]</span></span><br><span class="line"><span class="comment">#I will sort my list now</span></span><br><span class="line"><span class="comment">#Sorted shopping list is [&#x27;apple&#x27;, &#x27;banana&#x27;, &#x27;carrot&#x27;, &#x27;mango&#x27;, &#x27;rice&#x27;]</span></span><br><span class="line"><span class="comment">#The first item I will buy is apple</span></span><br><span class="line"><span class="comment">#I bought the  apple</span></span><br><span class="line"><span class="comment">#My shopping list is now [&#x27;banana&#x27;, &#x27;carrot&#x27;, &#x27;mango&#x27;, &#x27;rice&#x27;]</span></span><br></pre></td></tr></table></figure>
<p>列表是可变的<code>(Mutable)</code></p>
<h2 id="元组"><a href="#元组" class="headerlink" title="元组"></a>元组</h2><p>元组用于将多个对象保存在一起,但是元组是<code>(不可变的)</code>，不能编辑或者更改元组</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">zoo = (<span class="string">&#x27;python&#x27;</span>,<span class="string">&#x27;elephant&#x27;</span>,<span class="string">&#x27;penguin&#x27;</span>)</span><br><span class="line">print(<span class="string">&#x27;Number of animals in the zoo is &#x27;</span>,<span class="built_in">len</span>(zoo))</span><br><span class="line"></span><br><span class="line">new_zoo = <span class="string">&#x27;mokey&#x27;</span>,<span class="string">&#x27;camel&#x27;</span>,zoo</span><br><span class="line">print(<span class="string">&#x27;Number of cages in the new zoo is &#x27;</span>,<span class="built_in">len</span>(new_zoo))</span><br><span class="line">print(<span class="string">&#x27;All animals in new zoo are&#x27;</span>,new_zoo)</span><br><span class="line">print(<span class="string">&#x27;Animals brought from old zoo are &#x27;</span>,new_zoo[<span class="number">2</span>])</span><br><span class="line">print(<span class="string">&#x27;Last animal brought from old zoo is &#x27;</span>,new_zoo[<span class="number">2</span>][<span class="number">2</span>])</span><br><span class="line">print(<span class="string">&#x27;Number of animals in the new zoo is &#x27;</span>,<span class="built_in">len</span>(new_zoo)-<span class="number">1</span>+<span class="built_in">len</span>(new_zoo[<span class="number">2</span>]))</span><br><span class="line"></span><br><span class="line"><span class="comment">#Number of animals in the zoo is  3</span></span><br><span class="line"><span class="comment">#Number of cages in the new zoo is  3</span></span><br><span class="line"><span class="comment">#All animals in new zoo are (&#x27;mokey&#x27;, &#x27;camel&#x27;, (&#x27;python&#x27;, &#x27;elephant&#x27;, &#x27;penguin&#x27;))</span></span><br><span class="line"><span class="comment">#Animals brought from old zoo are  (&#x27;python&#x27;, &#x27;elephant&#x27;, &#x27;penguin&#x27;)</span></span><br><span class="line"><span class="comment">#Last animal brought from old zoo is  penguin</span></span><br><span class="line"><span class="comment">#Number of animals in the new zoo is  5</span></span><br></pre></td></tr></table></figure>


<h2 id="字典"><a href="#字典" class="headerlink" title="字典"></a>字典</h2><p><code>&#123;key,value&#125;</code>类似<code>map</code>的结构</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">ab = &#123;</span><br><span class="line">    <span class="string">&#x27;BUPT&#x27;</span>:<span class="string">&#x27;Changping&#x27;</span>,</span><br><span class="line">    <span class="string">&#x27;PKU&#x27;</span>:<span class="string">&#x27;Haidian&#x27;</span>,</span><br><span class="line">    <span class="string">&#x27;THU&#x27;</span>:<span class="string">&#x27;Haidian&#x27;</span>,</span><br><span class="line">    <span class="string">&#x27;WHU&#x27;</span>:<span class="string">&#x27;Wuhan&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line">print(<span class="string">&quot;BUPT&#x27;s address is &quot;</span>,ab[<span class="string">&#x27;BUPT&#x27;</span>])</span><br><span class="line"><span class="keyword">del</span> ab[<span class="string">&#x27;PKU&#x27;</span>]</span><br><span class="line"></span><br><span class="line">print(<span class="string">&#x27;\nTHere are &#x27;</span>,<span class="built_in">len</span>(ab),<span class="string">&#x27; contacts in the address-book\n&#x27;</span>)</span><br><span class="line"><span class="keyword">for</span> name,address <span class="keyword">in</span> ab.items():</span><br><span class="line">    print(<span class="string">&#x27;Contact &#x27;</span>,name,<span class="string">&#x27;at &#x27;</span>,address)</span><br><span class="line"></span><br><span class="line">ab[<span class="string">&#x27;HUST&#x27;</span>] = <span class="string">&#x27;Wuhan&#x27;</span></span><br><span class="line"><span class="keyword">if</span> <span class="string">&#x27;HUST&#x27;</span> <span class="keyword">in</span> ab:</span><br><span class="line">    print(<span class="string">&#x27;\nHUST is in &#x27;</span>,ab[<span class="string">&#x27;HUST&#x27;</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment">#BUPT&#x27;s address is  Changping</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#THere are  3  contacts in the address-book</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#Contact  BUPT at  Changping</span></span><br><span class="line"><span class="comment">#Contact  THU at  Haidian</span></span><br><span class="line"><span class="comment">#Contact  WHU at  Wuhan</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#HUST is in  Wuhan</span></span><br></pre></td></tr></table></figure>


<h2 id="序列"><a href="#序列" class="headerlink" title="序列"></a>序列</h2><p>序列的主要功能是<code>资格测试</code>和<code>索引操作</code>，他们能够允许直接获取序列中的特定项目，上面提到的列表、元组和字符串都拥有一种<code>slicing</code>（切片）运算</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">shoplist = [<span class="string">&#x27;apple&#x27;</span>,<span class="string">&#x27;mango&#x27;</span>,<span class="string">&#x27;carrot&#x27;</span>,<span class="string">&#x27;banana&#x27;</span>]</span><br><span class="line">name = <span class="string">&#x27;Lawted&#x27;</span></span><br><span class="line">print(<span class="string">&#x27;Item 1 is &#x27;</span>,shoplist[<span class="number">0</span>])   <span class="comment">#Item 1 is  apple</span></span><br><span class="line">print(<span class="string">&#x27;Item 2 is &#x27;</span>,shoplist[<span class="number">1</span>])   <span class="comment">#Item 2 is  mango</span></span><br><span class="line">print(<span class="string">&#x27;Item 3 is &#x27;</span>,shoplist[<span class="number">2</span>])   <span class="comment">#Item 3 is  carrot</span></span><br><span class="line">print(<span class="string">&#x27;Item 4 is &#x27;</span>,shoplist[<span class="number">3</span>])   <span class="comment">#Item 4 is  banana</span></span><br><span class="line">print(<span class="string">&#x27;Item -1 is &#x27;</span>,shoplist[-<span class="number">1</span>]) <span class="comment">#Item -1 is  banana</span></span><br><span class="line">print(<span class="string">&#x27;Item -2 is &#x27;</span>,shoplist[-<span class="number">2</span>]) <span class="comment">#Item -2 is  carrot</span></span><br><span class="line">print(<span class="string">&#x27;Character 0 is&#x27;</span>,name[<span class="number">0</span>])   <span class="comment">#Character 0 is L</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#Slicing on a list</span></span><br><span class="line">print(<span class="string">&#x27;Item 1 to 3 is&#x27;</span>,shoplist[<span class="number">1</span>:<span class="number">3</span>])     <span class="comment">#Item 1 to 3 is [&#x27;mango&#x27;, &#x27;carrot&#x27;]</span></span><br><span class="line">print(<span class="string">&#x27;Item 2 to end is&#x27;</span>,shoplist[<span class="number">2</span>:])    <span class="comment">#Item 2 to end is [&#x27;carrot&#x27;, &#x27;banana&#x27;]</span></span><br><span class="line">print(<span class="string">&#x27;Item 1 to -1 is&#x27;</span>,shoplist[<span class="number">1</span>:-<span class="number">1</span>])   <span class="comment">#Item 1 to -1 is [&#x27;mango&#x27;, &#x27;carrot&#x27;]</span></span><br><span class="line">print(<span class="string">&#x27;Item start to end is&#x27;</span>,shoplist[:]) <span class="comment">#Item start to end is [&#x27;apple&#x27;, &#x27;mango&#x27;, &#x27;carrot&#x27;, &#x27;banana&#x27;]</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#Slicing on a string</span></span><br><span class="line">print(<span class="string">&#x27;Character 1 to 3&#x27;</span>,name[<span class="number">1</span>:<span class="number">3</span>])        <span class="comment">#Character 1 to 3 aw</span></span><br><span class="line">print(<span class="string">&#x27;Character 2 to end is&#x27;</span>,name[<span class="number">2</span>:])    <span class="comment">#Character 2 to end is wted</span></span><br><span class="line">print(<span class="string">&#x27;Character 1 to -1 is&#x27;</span>,name[<span class="number">1</span>:-<span class="number">1</span>])   <span class="comment">#Character 1 to -1 is awte</span></span><br><span class="line">print(<span class="string">&#x27;Character start to end is&#x27;</span>,name[:]) <span class="comment">#Character start to end is Lawted</span></span><br></pre></td></tr></table></figure>
<p>索引操作使用复数，在这种情况下，位置技术将从队列的末尾开始，因此<code>shoplist[-1]</code>指的是序列最后一个项目，序列的切片将包括起始位置，但不包括结束位置</p>
<p>因此，<code>shoplist[:-1]</code>返回一组序列切片，从第一个到最后一个，但是不包括最后一个</p>
<p>同样的类似<code>for</code>循环，我们可以在切片操作中提供第三个参数，这一参数被视为切片的步长</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">shoplist = [<span class="string">&#x27;apple&#x27;</span>,<span class="string">&#x27;mango&#x27;</span>,<span class="string">&#x27;carrot&#x27;</span>,<span class="string">&#x27;banana&#x27;</span>]</span><br><span class="line">print(shoplist[::<span class="number">1</span>]) <span class="comment">#[&#x27;apple&#x27;, &#x27;mango&#x27;, &#x27;carrot&#x27;, &#x27;banana&#x27;]</span></span><br><span class="line">print(shoplist[::<span class="number">2</span>]) <span class="comment">#[&#x27;apple&#x27;, &#x27;carrot&#x27;]</span></span><br><span class="line">print(shoplist[::-<span class="number">1</span>])<span class="comment">#[&#x27;banana&#x27;, &#x27;carrot&#x27;, &#x27;mango&#x27;, &#x27;apple&#x27;]</span></span><br></pre></td></tr></table></figure>
<h2 id="集合"><a href="#集合" class="headerlink" title="集合"></a>集合</h2><p>集合<code>(set)</code>是简单对象的无序集合<code>(Collection)</code>当集合中的项目存在与否比起次序或其出现次数更加重要时候，就会使用集合，通过集合，测试某些对象的资格或情况，检查它们是否其他集合的子集，找到两个集合的交集</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">st = <span class="built_in">set</span>([<span class="string">&#x27;brazil&#x27;</span>,<span class="string">&#x27;russia&#x27;</span>,<span class="string">&#x27;india&#x27;</span>])</span><br><span class="line">print(<span class="string">&#x27;india&#x27;</span> <span class="keyword">in</span> st) </span><br><span class="line">print(<span class="string">&#x27;usa&#x27;</span> <span class="keyword">in</span> st)</span><br><span class="line">st1 = st.copy()</span><br><span class="line">st1.add(<span class="string">&#x27;china&#x27;</span>)</span><br><span class="line">print(st1.issuperset(st))</span><br><span class="line">st1.remove(<span class="string">&#x27;russia&#x27;</span>)</span><br><span class="line">print(st &amp; st1)</span><br><span class="line"></span><br><span class="line"><span class="comment"># True</span></span><br><span class="line"><span class="comment"># False</span></span><br><span class="line"><span class="comment"># True</span></span><br><span class="line"><span class="comment"># &#123;&#x27;brazil&#x27;, &#x27;india&#x27;&#125;</span></span><br></pre></td></tr></table></figure>


<h2 id="引用"><a href="#引用" class="headerlink" title="引用"></a>引用</h2><p>当创建了一个对象并将其分配给某个变量时，变量会<code>refer</code>某个对象，并且它不会代表对象本身。他只是将名称<code>bingding </code>给了那一个对象</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">shoplist = [<span class="string">&#x27;apple&#x27;</span>,<span class="string">&#x27;mango&#x27;</span>,<span class="string">&#x27;carrot&#x27;</span>,<span class="string">&#x27;banana&#x27;</span>]</span><br><span class="line">mylist = shoplist</span><br><span class="line"><span class="keyword">del</span> shoplist[<span class="number">0</span>]</span><br><span class="line">print(<span class="string">&#x27;shoplist is &#x27;</span>,shoplist) <span class="comment"># shoplist is  [&#x27;mango&#x27;, &#x27;carrot&#x27;, &#x27;banana&#x27;]</span></span><br><span class="line">print(<span class="string">&#x27;mylist is &#x27;</span>,mylist)     <span class="comment"># mylist is  [&#x27;mango&#x27;, &#x27;carrot&#x27;, &#x27;banana&#x27;]</span></span><br><span class="line"></span><br><span class="line">mylist = shoplist[:]</span><br><span class="line"><span class="keyword">del</span> mylist[<span class="number">0</span>]</span><br><span class="line">print(<span class="string">&#x27;shoplist is &#x27;</span>,shoplist) <span class="comment"># shoplist is  [&#x27;mango&#x27;, &#x27;carrot&#x27;, &#x27;banana&#x27;]</span></span><br><span class="line">print(<span class="string">&#x27;mylist is &#x27;</span>,mylist)     <span class="comment"># mylist is  [&#x27;carrot&#x27;, &#x27;banana&#x27;]</span></span><br></pre></td></tr></table></figure>


<h2 id="字符串plus"><a href="#字符串plus" class="headerlink" title="字符串plus"></a>字符串plus</h2><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">name = <span class="string">&#x27;Lawted&#x27;</span></span><br><span class="line"><span class="keyword">if</span> name.startswith(<span class="string">&#x27;Law&#x27;</span>):</span><br><span class="line">    print(<span class="string">&#x27;Yes it is start with Law&#x27;</span>)</span><br><span class="line"><span class="keyword">if</span> <span class="string">&#x27;a&#x27;</span> <span class="keyword">in</span> name:</span><br><span class="line">    print(<span class="string">&#x27;Yes it contains the string a&#x27;</span>)</span><br><span class="line"><span class="keyword">if</span> name.find(<span class="string">&#x27;ted&#x27;</span>) != -<span class="number">1</span>:</span><br><span class="line">    print(<span class="string">&#x27;Yes,it contains the string &quot;ted&quot;&#x27;</span>)</span><br><span class="line"></span><br><span class="line">delimiter = <span class="string">&#x27;-&#x27;</span></span><br><span class="line">mylist = [<span class="string">&#x27;Brazil&#x27;</span>,<span class="string">&#x27;USA&#x27;</span>,<span class="string">&#x27;China&#x27;</span>]</span><br><span class="line">print(delimiter.join(mylist))  <span class="comment">#Brazil-USA-China</span></span><br></pre></td></tr></table></figure>
<p>类似JS的写法</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/25/Python/python-%E6%A8%A1%E5%9D%97/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/04/25/Python/python-%E6%A8%A1%E5%9D%97/" class="post-title-link" itemprop="url">Python - 模块</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2021-04-25 21:13:22" itemprop="dateCreated datePublished" datetime="2021-04-25T21:13:22+08:00">2021-04-25</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-05-07 09:34:02" itemprop="dateModified" datetime="2021-05-07T09:34:02+08:00">2021-05-07</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="模块"><a href="#模块" class="headerlink" title="模块"></a>模块</h2><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> sys</span><br><span class="line">print(<span class="string">&#x27;The command lin arguments are: &#x27;</span>)</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> sys.argv:</span><br><span class="line">    print(i)</span><br><span class="line">print(<span class="string">&#x27;\n\nTHE PYTHONPATH is &#x27;</span>,sys.path,<span class="string">&#x27;\n&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p><code>import</code>后使用<code>.argv</code>的变量，如果希望直接将<code>argv</code>变量导入程序（避免每次都要输入<code>sys.</code>）可以直接使用<code>from sys import argv</code>来实现</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">from</span> math <span class="keyword">import</span> sqrt</span><br><span class="line">print(<span class="string">&#x27;Square root of 16 is&#x27;</span>,sqrt(<span class="number">16</span>))</span><br></pre></td></tr></table></figure>


<h3 id="模块的-name"><a href="#模块的-name" class="headerlink" title="模块的__name__"></a>模块的<code>__name__</code></h3><p>为了查看模块是为自己所用还是从其他的模块中导入过来的，可以使用模块的<code>__name__</code>属性来实现</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    print(<span class="string">&#x27;This program is being run by itself&#x27;</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">    print(<span class="string">&#x27;I am being imported from another module&#x27;</span>)</span><br></pre></td></tr></table></figure>


<h3 id="编写一个自己的模块"><a href="#编写一个自己的模块" class="headerlink" title="编写一个自己的模块"></a>编写一个自己的模块</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment">#main.py</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> demo01</span><br><span class="line">demo01.say_hi()</span><br><span class="line">print(<span class="string">&#x27;Version: &#x27;</span>,demo01.__version__)</span><br></pre></td></tr></table></figure>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment">#demo01.py</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">say_hi</span>():</span></span><br><span class="line">    print(<span class="string">&#x27;Hi,this is mymodule speaking.&#x27;</span>)</span><br><span class="line">__version__ = <span class="string">&#x27;0.1&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#Hi,this is mymodule speaking.</span></span><br><span class="line"><span class="comment">#Version:  0.1</span></span><br></pre></td></tr></table></figure>
<p>通过使用<code>import</code>可以把<code>demo01</code>的模块导入，同样的也可以使用<code>from ..import..</code>语句</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment">#main.py</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> demo01 <span class="keyword">import</span> say_hi ,__version__</span><br><span class="line">say_hi()</span><br><span class="line">print(<span class="string">&#x27;Version: &#x27;</span>,__version__)</span><br></pre></td></tr></table></figure>
<p>需要注意</p>
<ul>
<li>如果使用<code>from .. import..</code>语句的话，在调用的时候就不用写<code>demo01.</code></li>
<li>如果<code>main</code>中的模块里面已经存在了<code>__version__</code>那么会产生冲突</li>
</ul>
<h2 id="dir函数"><a href="#dir函数" class="headerlink" title="dir函数"></a>dir函数</h2><p>内置的<code>dir()</code>函数能够返回有对象所定义的名称列表，如果这一对象是一个模块，则该列表会包括函数内所定义的函数、类与变量</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">a = <span class="number">5</span></span><br><span class="line">print(<span class="built_in">dir</span>())</span><br><span class="line"></span><br><span class="line"><span class="comment"># [&#x27;__annotations__&#x27;, &#x27;__builtins__&#x27;, &#x27;__cached__&#x27;, &#x27;__doc__&#x27;, &#x27;__file__&#x27;, &#x27;__loader__&#x27;, &#x27;__name__&#x27;, &#x27;__package__&#x27;, &#x27;__spec__&#x27;, &#x27;a&#x27;]</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">del</span> a</span><br><span class="line">print(<span class="built_in">dir</span>())</span><br><span class="line"><span class="comment"># [&#x27;__annotations__&#x27;, &#x27;__builtins__&#x27;, &#x27;__cached__&#x27;, &#x27;__doc__&#x27;, &#x27;__file__&#x27;, &#x27;__loader__&#x27;, &#x27;__name__&#x27;, &#x27;__package__&#x27;, &#x27;__spec__&#x27;]</span></span><br></pre></td></tr></table></figure>


<h2 id="包"><a href="#包" class="headerlink" title="包"></a>包</h2><p>包是指一个包含模块与一个特殊的<code>__init__.py</code>文件的文件夹，后者向Python表明这一文件夹是特别的，因为包含了Python模块</p>
<p>在文件系统上组织你的代码，并确保每个目录都定义了一个<code>__init__.py</code>文件。 例如：</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">graphics/</span><br><span class="line">    __init__.py</span><br><span class="line">    primitive/</span><br><span class="line">        __init__.py</span><br><span class="line">        line.py</span><br><span class="line">        fill.py</span><br><span class="line">        text.py</span><br><span class="line">    formats/</span><br><span class="line">        __init__.py</span><br><span class="line">        png.py</span><br><span class="line">        jpg.py</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/22/Python/python-%E5%87%BD%E6%95%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/04/22/Python/python-%E5%87%BD%E6%95%B0/" class="post-title-link" itemprop="url">python-函数</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2021-04-22 20:04:35" itemprop="dateCreated datePublished" datetime="2021-04-22T20:04:35+08:00">2021-04-22</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-05-07 09:33:51" itemprop="dateModified" datetime="2021-05-07T09:33:51+08:00">2021-05-07</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="函数"><a href="#函数" class="headerlink" title="函数"></a>函数</h2><p>函数可以通过关键字<code>def</code>来定义，记得冒号结尾</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">say_hello</span>():</span></span><br><span class="line">    print(<span class="string">&#x27;hello world&#x27;</span>)</span><br><span class="line"></span><br><span class="line">say_hello()</span><br></pre></td></tr></table></figure>
<p>传参数</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">print_max</span>(<span class="params">a,b</span>):</span></span><br><span class="line">    <span class="keyword">if</span> a&gt;b:</span><br><span class="line">        print(a,<span class="string">&#x27; bigger&#x27;</span>)</span><br><span class="line">    <span class="keyword">elif</span> a==b:</span><br><span class="line">        print(a,<span class="string">&#x27;is equals to &#x27;</span>,b)</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(b,<span class="string">&#x27;is bigger&#x27;</span>)</span><br><span class="line"></span><br><span class="line">print_max(<span class="number">3</span>,<span class="number">4</span>)</span><br></pre></td></tr></table></figure>


<h3 id="局部变量"><a href="#局部变量" class="headerlink" title="局部变量"></a>局部变量</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">x = <span class="number">50</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">x</span>):</span></span><br><span class="line">    print(<span class="string">&#x27;x is &#x27;</span>,x)</span><br><span class="line">    x = <span class="number">2</span></span><br><span class="line">    print(<span class="string">&#x27;x is &#x27;</span>,x,<span class="string">&#x27;now&#x27;</span>)</span><br><span class="line"></span><br><span class="line">func(x)</span><br><span class="line">print(<span class="string">&#x27;x is still&#x27;</span>,x)</span><br><span class="line"><span class="comment">#x is  50</span></span><br><span class="line"><span class="comment">#x is  2 now</span></span><br><span class="line"><span class="comment">#x is still 50</span></span><br></pre></td></tr></table></figure>


<h3 id="global-语句"><a href="#global-语句" class="headerlink" title="global 语句"></a>global 语句</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">x = <span class="number">50</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>():</span></span><br><span class="line">    <span class="keyword">global</span> x</span><br><span class="line"></span><br><span class="line">    print(<span class="string">&#x27;x is &#x27;</span>,x)</span><br><span class="line">    x = <span class="number">2</span></span><br><span class="line">    print(<span class="string">&#x27;x is &#x27;</span>,x,<span class="string">&#x27;now&#x27;</span>)</span><br><span class="line"></span><br><span class="line">func()</span><br><span class="line">print(<span class="string">&#x27;x is still&#x27;</span>,x)</span><br><span class="line"><span class="comment">#x is  50</span></span><br><span class="line"><span class="comment">#x is  2 now</span></span><br><span class="line"><span class="comment">#x is still 2</span></span><br></pre></td></tr></table></figure>
<p><code>global</code>语句便可清楚看出这一变量式再最外面代码块定义的</p>
<h3 id="默认参数值"><a href="#默认参数值" class="headerlink" title="默认参数值"></a>默认参数值</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">say</span>(<span class="params">message,times = <span class="number">1</span></span>):</span></span><br><span class="line">    print(message*times)</span><br><span class="line">say(<span class="string">&#x27;hello&#x27;</span>)  <span class="comment">#hello</span></span><br><span class="line">say(<span class="string">&#x27;word&#x27;</span>,<span class="number">5</span>) <span class="comment">#wordwordwordwordword</span></span><br></pre></td></tr></table></figure>


<h3 id="关键字参数"><a href="#关键字参数" class="headerlink" title="关键字参数"></a>关键字参数</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">a,b=<span class="number">5</span>,c=<span class="number">10</span></span>):</span></span><br><span class="line">    print(<span class="string">&#x27;a is &#x27;</span>,a,<span class="string">&#x27;and b is &#x27;</span>,b,<span class="string">&#x27;and c is &#x27;</span>,c)</span><br><span class="line">func(<span class="number">3</span>,<span class="number">7</span>)         <span class="comment">#a is  3 and b is  7 and c is  10</span></span><br><span class="line">func(<span class="number">25</span>,c=<span class="number">14</span>)     <span class="comment">#a is  25 and b is  5 and c is  14</span></span><br><span class="line">func(c=<span class="number">50</span>,a=<span class="number">100</span>)  <span class="comment">#a is  100 and b is  5 and c is  50</span></span><br></pre></td></tr></table></figure>
<p>相比于默认参数值，关键字参数可以指定参数</p>
<h3 id="可变参数"><a href="#可变参数" class="headerlink" title="可变参数"></a>可变参数</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">total</span>(<span class="params">a=<span class="number">5</span>,*number,**phonebook</span>):</span></span><br><span class="line">    print(<span class="string">&#x27;a&#x27;</span>,a)</span><br><span class="line">    <span class="keyword">for</span> string_item <span class="keyword">in</span> numbers:</span><br><span class="line">        print(<span class="string">&#x27;single_item&#x27;</span>, single_item)</span><br><span class="line">    <span class="keyword">for</span> first_part,second_part <span class="keyword">in</span> phonebook.items():</span><br><span class="line">        print(first_part,second_part)</span><br><span class="line">print(total(<span class="number">10</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,jack=<span class="number">123</span>,john=<span class="number">234</span>,lawted=<span class="number">345</span>))</span><br><span class="line"><span class="comment">#a 10</span></span><br><span class="line"><span class="comment">#single_item 1</span></span><br><span class="line"><span class="comment">#single_item 2</span></span><br><span class="line"><span class="comment">#single_item 3</span></span><br><span class="line"><span class="comment">#jack 123</span></span><br><span class="line"><span class="comment">#john 234</span></span><br><span class="line"><span class="comment">#lawted 345</span></span><br><span class="line"><span class="comment">#True </span></span><br></pre></td></tr></table></figure>
<p>一个<code>*param</code>的星号参数，就是一个元组</p>
<p>两个<code>**param</code>的星号参数时候，所有的关键字参数汇集成一个名为<code>param</code>的字典</p>
<h3 id="return"><a href="#return" class="headerlink" title="return"></a>return</h3><p>如果没有写，那就是返回<code>None</code></p>
<h3 id="docstrings"><a href="#docstrings" class="headerlink" title="docstrings"></a>docstrings</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">print_max</span>(<span class="params">x, y</span>):</span></span><br><span class="line">    <span class="string">&#x27;&#x27;&#x27;打印两个数中的最大数</span></span><br><span class="line"><span class="string">    两个数都应该是整数&#x27;&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line">    x = <span class="built_in">int</span>(x)</span><br><span class="line">    y = <span class="built_in">int</span>(y)</span><br><span class="line">    <span class="keyword">if</span> x &gt; y:</span><br><span class="line">        print(x, <span class="string">&#x27;is bigger&#x27;</span>)</span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        print(y, <span class="string">&#x27;is bigger&#x27;</span>)</span><br><span class="line"></span><br><span class="line">print_max(<span class="number">3</span>, <span class="number">5</span>)</span><br><span class="line">print(print_max.__doc__)</span><br><span class="line"></span><br><span class="line"><span class="comment">#5 is bigger</span></span><br><span class="line"><span class="comment">#打印两个数中的最大数</span></span><br><span class="line"><span class="comment">#    两个数都应该是整数</span></span><br></pre></td></tr></table></figure>
<p>类似javadoc，写在注释里面成了函数的<code>doc</code></p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/22/Python/python-%E6%8E%A7%E5%88%B6%E6%B5%81/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/04/22/Python/python-%E6%8E%A7%E5%88%B6%E6%B5%81/" class="post-title-link" itemprop="url">python-控制流</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2021-04-22 19:42:40" itemprop="dateCreated datePublished" datetime="2021-04-22T19:42:40+08:00">2021-04-22</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-05-07 09:33:56" itemprop="dateModified" datetime="2021-05-07T09:33:56+08:00">2021-05-07</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id="if语句"><a href="#if语句" class="headerlink" title="if语句"></a><code>if</code>语句</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">number = <span class="number">20</span></span><br><span class="line">guess = <span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">&#x27;Enter a number: &#x27;</span>))</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> guess == number:</span><br><span class="line">    print(<span class="string">&#x27;that\&#x27;s it&#x27;</span>)</span><br><span class="line"><span class="keyword">elif</span> guess &gt;number:</span><br><span class="line">    print(<span class="string">&#x27;guess smaller&#x27;</span>)</span><br><span class="line"><span class="keyword">else</span> :</span><br><span class="line">    print(<span class="string">&#x27;guess bigger&#x27;</span>)</span><br></pre></td></tr></table></figure>


<p>记得<code>if</code>没有了括号 ，但是后面加了一个<code>:</code> , 注意<code>python</code>中没有<code>switch</code>语句，但是可以有<code>字典</code>来快速完成</p>
<h3 id="while语句"><a href="#while语句" class="headerlink" title="while语句"></a><code>while</code>语句</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">number = <span class="number">20</span></span><br><span class="line">running = <span class="literal">True</span></span><br><span class="line"><span class="keyword">while</span> running:</span><br><span class="line">    guess = <span class="built_in">int</span> (<span class="built_in">input</span>(<span class="string">&#x27;Enter a integer: &#x27;</span>))</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> guess == number:</span><br><span class="line">        print(<span class="string">&#x27;that\&#x27;s it&#x27;</span>)</span><br><span class="line">        running = <span class="literal">False</span></span><br><span class="line">    <span class="keyword">elif</span> guess &gt;number:</span><br><span class="line">        print(<span class="string">&#x27;guesssmaller&#x27;</span>)</span><br><span class="line">    <span class="keyword">else</span> :</span><br><span class="line">        print(<span class="string">&#x27;guess bigger&#x27;</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">    print(<span class="string">&#x27;finished&#x27;</span>)</span><br></pre></td></tr></table></figure>


<h3 id="for语句"><a href="#for语句" class="headerlink" title="for语句"></a><code>for</code>语句</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">5</span>): <span class="comment"># 输出不包含5</span></span><br><span class="line">	print(i)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">    print(<span class="string">&#x27;over&#x27;</span>)</span><br><span class="line">    </span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">10</span>,<span class="number">2</span>): <span class="comment">#间隔位2</span></span><br><span class="line">	print(i)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line">    print(<span class="string">&#x27;over&#x27;</span>)</span><br></pre></td></tr></table></figure>


<h3 id="break语句"><a href="#break语句" class="headerlink" title="break语句"></a><code>break</code>语句</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line">    s = <span class="built_in">input</span>(<span class="string">&#x27;Enter somthing: &#x27;</span>)</span><br><span class="line">    <span class="keyword">if</span> s == <span class="string">&#x27;quit&#x27;</span>:</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    print(<span class="string">&#x27;length of the string is &#x27;</span><span class="built_in">len</span>(s))</span><br><span class="line">print(<span class="string">&#x27;done&#x27;</span>)</span><br></pre></td></tr></table></figure>


<h3 id="continue语句"><a href="#continue语句" class="headerlink" title="continue语句"></a><code>continue</code>语句</h3><p>AS U THINK~</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/22/Python/python-%E8%BF%90%E7%AE%97%E7%AC%A6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/04/22/Python/python-%E8%BF%90%E7%AE%97%E7%AC%A6/" class="post-title-link" itemprop="url">python-运算符</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2021-04-22 19:17:58" itemprop="dateCreated datePublished" datetime="2021-04-22T19:17:58+08:00">2021-04-22</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-05-07 09:34:14" itemprop="dateModified" datetime="2021-05-07T09:34:14+08:00">2021-05-07</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h3 id=""><a href="#" class="headerlink" title="+"></a>+</h3><ul>
<li>两个对象相加</li>
<li><code>3+5</code> 输出 <code>8</code></li>
<li><code>&#39;a&#39;+&#39;b&#39;</code>输出<code>&#39;ab&#39;</code></li>
</ul>
<h3 id="-1"><a href="#-1" class="headerlink" title="-"></a>-</h3><ul>
<li><code>50-24</code>输出26</li>
</ul>
<h3 id="-2"><a href="#-2" class="headerlink" title="*"></a>*</h3><ul>
<li>两个数的乘积<code>a*3</code></li>
<li>字符串重复指定次数<code>&#39;la&#39;*3</code>输出<code>&#39;lalala&#39;</code></li>
</ul>
<h3 id="-3"><a href="#-3" class="headerlink" title="**"></a>**</h3><ul>
<li><p>返回<code>x</code>的<code>y</code>次方</p>
</li>
<li><p><code>3**4</code>输出<code>81</code></p>
</li>
</ul>
<h3 id="-4"><a href="#-4" class="headerlink" title="/"></a>/</h3><ul>
<li><p>输出<code>x</code>除<code>y</code></p>
</li>
<li><p><code>1/3</code>等于<code>0.3333333333333333</code></p>
</li>
</ul>
<h3 id="-5"><a href="#-5" class="headerlink" title="//"></a>//</h3><ul>
<li><p>除法后向下取整</p>
</li>
<li><p><code>13//3</code>输出<code>4</code></p>
</li>
<li><p><code>-13//3</code>输出<code>-5</code></p>
<p>​            </p>
</li>
</ul>
<h3 id="-6"><a href="#-6" class="headerlink" title="%"></a>%</h3><ul>
<li>返回除法运算后的余数</li>
</ul>
<h3 id="lt-lt"><a href="#lt-lt" class="headerlink" title="&lt;&lt;"></a>&lt;&lt;</h3><ul>
<li>将数字的二进制位向左移</li>
</ul>
<h3 id="gt-gt"><a href="#gt-gt" class="headerlink" title="&gt;&gt;"></a>&gt;&gt;</h3><ul>
<li>将数字的位向右移动指定位数</li>
</ul>
<h3 id="amp"><a href="#amp" class="headerlink" title="&amp;"></a>&amp;</h3><ul>
<li>按位与</li>
</ul>
<h3 id="-7"><a href="#-7" class="headerlink" title="|"></a>|</h3><ul>
<li>按位或</li>
</ul>
<h3 id="-8"><a href="#-8" class="headerlink" title="^"></a>^</h3><ul>
<li>按位异或</li>
</ul>
<h3 id="-9"><a href="#-9" class="headerlink" title="~"></a>~</h3><ul>
<li>按位取反</li>
</ul>
<h3 id="lt"><a href="#lt" class="headerlink" title="&lt;"></a>&lt;</h3><ul>
<li>小于</li>
</ul>
<h3 id="gt"><a href="#gt" class="headerlink" title="&gt;"></a>&gt;</h3><ul>
<li>大于</li>
</ul>
<h3 id="lt-1"><a href="#lt-1" class="headerlink" title="&lt;="></a>&lt;=</h3><ul>
<li>小于等于</li>
</ul>
<h3 id="gt-1"><a href="#gt-1" class="headerlink" title="&gt;="></a>&gt;=</h3><ul>
<li>大于等于</li>
</ul>
<h3 id="-10"><a href="#-10" class="headerlink" title="=="></a>==</h3><ul>
<li>比较两个对象是否相等</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">x = <span class="string">&#x27;str&#x27;</span></span><br><span class="line">y = <span class="string">&#x27;stR&#x27;</span></span><br><span class="line">print(x==y) <span class="comment">#false</span></span><br></pre></td></tr></table></figure>


<h3 id="-11"><a href="#-11" class="headerlink" title="!="></a>!=</h3><ul>
<li>比较两个对象是否不相等</li>
</ul>
<h3 id="not-布尔非"><a href="#not-布尔非" class="headerlink" title="not(布尔非)"></a>not(布尔非)</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">x = <span class="number">1</span></span><br><span class="line">print(<span class="keyword">not</span> x) <span class="comment">#False</span></span><br></pre></td></tr></table></figure>


<h3 id="and-布尔与"><a href="#and-布尔与" class="headerlink" title="and(布尔与)"></a>and(布尔与)</h3><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">x = <span class="literal">True</span></span><br><span class="line">y = <span class="literal">False</span></span><br><span class="line">print(x <span class="keyword">and</span> y) <span class="comment">#False</span></span><br></pre></td></tr></table></figure>


<h2 id="or-布尔或"><a href="#or-布尔或" class="headerlink" title="or(布尔或)"></a>or(布尔或)</h2><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">x = <span class="literal">True</span></span><br><span class="line">y = <span class="literal">False</span></span><br><span class="line">print(x <span class="keyword">and</span> y) <span class="comment">#True</span></span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/20/Python/Python-%E5%AD%97%E7%AC%A6%E4%B8%B2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/04/20/Python/Python-%E5%AD%97%E7%AC%A6%E4%B8%B2/" class="post-title-link" itemprop="url">Python - 字符串</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2021-04-20 21:13:22" itemprop="dateCreated datePublished" datetime="2021-04-20T21:13:22+08:00">2021-04-20</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-05-07 09:34:20" itemprop="dateModified" datetime="2021-05-07T09:34:20+08:00">2021-05-07</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="format"><a href="#format" class="headerlink" title="format()"></a>format()</h2><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">age = <span class="number">20</span></span><br><span class="line">name = <span class="string">&#x27;lawted&#x27;</span></span><br><span class="line">print(<span class="string">&#x27;&#123;0&#125; was &#123;1&#125; years old when he wrote this code&#x27;</span>.<span class="built_in">format</span>(name,age))</span><br><span class="line">print(name + <span class="string">&#x27; is &#x27;</span> + <span class="built_in">str</span>(age) + <span class="string">&#x27; old&#x27;</span>)</span><br><span class="line"><span class="comment">#lawted was 20 years old when he wrote this code</span></span><br><span class="line"><span class="comment">#lawted is 20 old</span></span><br></pre></td></tr></table></figure>
<p><code>&#123;0&#125;</code>对应变量<code>name</code>，<code>&#123;1&#125;</code>对应变量<code>age</code>，注意<code>&#123;&#125;</code>中的数字可以去掉</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">age = <span class="number">20</span></span><br><span class="line">name = <span class="string">&#x27;lawted&#x27;</span></span><br><span class="line">print(<span class="string">&#x27;&#123;&#125; was &#123;&#125; years old when he wrote this code&#x27;</span>.<span class="built_in">format</span>(name,age))</span><br><span class="line">print(name + <span class="string">&#x27; is &#x27;</span> + <span class="built_in">str</span>(age) + <span class="string">&#x27; old&#x27;</span>)</span><br></pre></td></tr></table></figure>
<p>还有类似<code>JavaScript</code>的写法</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">name + <span class="string">&#x27;is&#x27;</span> + <span class="built_in">str</span>(age) + <span class="string">&#x27;old&#x27;</span></span><br></pre></td></tr></table></figure>


<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">print(<span class="string">&#x27;&#123;0:.3f&#125;&#x27;</span>.<span class="built_in">format</span>(<span class="number">1.0</span>/<span class="number">3</span>))                                                <span class="comment">#0.333</span></span><br><span class="line">print(<span class="string">&#x27;&#123;0:_^11&#125;&#x27;</span>.<span class="built_in">format</span>(<span class="string">&#x27;hello&#x27;</span>))                                             <span class="comment">#___hello___</span></span><br><span class="line">print(<span class="string">&#x27;&#123;name&#125; wrote &#123;code&#125;&#x27;</span>.<span class="built_in">format</span>(name = <span class="string">&#x27;Lawted&#x27;</span>,code = <span class="string">&#x27;code of python&#x27;</span>))  <span class="comment">#Lawted wrote code of python</span></span><br></pre></td></tr></table></figure>
<p>可以用<code>end=&#39;&#39;</code>来指定结尾不换行</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">print(<span class="string">&#x27;a&#x27;</span>,end=<span class="string">&#x27;&#x27;</span>)</span><br><span class="line">print(<span class="string">&#x27;b&#x27;</span>,end=<span class="string">&#x27;&#x27;</span>) <span class="comment">#ab</span></span><br><span class="line"><span class="comment"># 同样可以用来加别的结尾</span></span><br><span class="line">print(<span class="string">&#x27;a&#x27;</span>,end=<span class="string">&#x27;+&#x27;</span>)</span><br><span class="line">print(<span class="string">&#x27;b&#x27;</span>,end=<span class="string">&#x27;&#x27;</span>)  <span class="comment">#a+b</span></span><br></pre></td></tr></table></figure>


<h2 id="转义"><a href="#转义" class="headerlink" title="转义"></a>转义</h2><p>可以通过<code>\</code>来连接一个分开的句子,被称为<code>显式连接行</code></p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">s = <span class="string">&#x27;&#x27;&#x27;This is a multi-line string.\</span></span><br><span class="line"><span class="string">This is the second line.&#x27;&#x27;&#x27;</span></span><br><span class="line">print(s)</span><br><span class="line"></span><br><span class="line"><span class="comment"># This is a multi-line string.This is the second line.</span></span><br></pre></td></tr></table></figure>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">i = \</span><br><span class="line"><span class="number">5</span></span><br><span class="line"></span><br><span class="line">i = <span class="number">5</span></span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/04/20/JS%20U%20DONT%20KNOW%202/%E7%9F%AD%E8%B7%AF/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Lawted Wu">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Lawted's Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/2021/04/20/JS%20U%20DONT%20KNOW%202/%E7%9F%AD%E8%B7%AF/" class="post-title-link" itemprop="url">短路</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2021-04-20 12:40:39" itemprop="dateCreated datePublished" datetime="2021-04-20T12:40:39+08:00">2021-04-20</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">Edited on</span>
        <time title="Modified: 2021-05-07 09:33:13" itemprop="dateModified" datetime="2021-05-07T09:33:13+08:00">2021-05-07</time>
      </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="用-和-amp-amp-来短路"><a href="#用-和-amp-amp-来短路" class="headerlink" title="用|| 和 &amp;&amp; 来短路"></a>用|| 和 &amp;&amp; 来短路</h2><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">dosomething</span>(<span class="params">a</span>) </span>&#123; </span><br><span class="line">    <span class="keyword">if</span>(a &amp;&amp; a.cool)&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>如果没有<code>a</code>也就不用执行<code>a.cool</code></p>
<figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">dosomething</span>(<span class="params">a</span>) </span>&#123; </span><br><span class="line">    <span class="keyword">if</span>(a.cache||inita())&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>如果没有 <code>a.cache</code>就需要去执行<code>inita()</code>来生成</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><span class="space">&hellip;</span><a class="page-number" href="/page/7/">7</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right" aria-label="Next page"></i></a>
  </nav>


<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Lawted Wu</span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="Total Visitors">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="Total Views">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  


  <script src="https://cdn.jsdelivr.net/npm/darkmode-js@1.5.7/lib/darkmode-js.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>


<script>
var options = {
  bottom: '64px', // default: '32px'
  right: '32px', // default: '32px'
  left: 'unset', // default: 'unset'
  time: '0.5s', // default: '0.3s'
  mixColor: '#fff', // default: '#fff'
  backgroundColor: '#fff',  // default: '#fff'
  buttonColorDark: '#000',  // default: '#100f2c'
  buttonColorLight: '#fff', // default: '#fff'
  saveInCookies: true, // default: true,
  label: ' ', // default: ''
  autoMatchOsTheme: true // default: true
}
const darkmode = new Darkmode(options);
darkmode.showWidget();
</script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>

  






  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
